import { Problem } from "@/types/problem";
import { ProblemSearchDto } from "./dto/problem.dto";

import { request } from "@/service/request";

/**
 * 获取已处理问题列表
 * @param page
 * @param size
 * @returns
 */
export const getTreatedProblemList = async (
    page: number,
    size: number,
    conditions?: Partial<ProblemSearchDto>
): Promise<{ count: number; problems: Problem[] }> => {
    try {
        return await request<{ count: number; problems: Problem[] }>(
            "/problem/get-processed-feedback",
            {
                page: page,
                size: size,
                ...conditions,
            }
        );
    } catch (err) {
        throw err;
    }
};

/**
 * 获取未处理问题列表
 * @param page
 * @param size
 * @returns
 */
export const getUntreatedProblemList = async (
    page: number,
    size: number,
    conditions?: Partial<ProblemSearchDto>
): Promise<{ count: number; problems: Problem[] }> => {
    try {
        return await request<{ count: number; problems: Problem[] }>(
            "/problem/get-unprocessed-feedback",
            {
                page: page,
                size: size,
                ...conditions,
            }
        );
    } catch (err) {
        throw err;
    }
};

/**
 * 回复问题
 * @param id
 * @param response
 * @returns
 */
export const responseProblem = async (id: string, response: string) => {
    try {
        return await request("/problem/response-feedback", {
            id: id,
            response: response,
        });
    } catch (err) {
        throw err;
    }
};

/**
 * 删除问题
 * @param id
 * @returns
 */
export const deleteProblem = async (id: string) => {
    try {
        return await request("/problem/delete-question-feedback", { id: id });
    } catch (err) {
        throw err;
    }
};
